import { request } from '@/utils/request'
import type { SalesOrder, SalesOrderSearch } from '@/types/sales-order'
import type { PageQuery } from '@/types/api'

// 获取销售订单列表
export function getSalesOrderList(params?: SalesOrderSearch) {
  return request<SalesOrder[]>({
    url: '/sales-order/list',
    method: 'get',
    params
  })
}

// 分页获取销售订单列表
export function getSalesOrderPage(params: PageQuery & SalesOrderSearch) {
  return request<{
    rows: SalesOrder[]
    total: number
    pages?: number
    current?: number
    size?: number
  }>({
    url: '/sales-order/page',
    method: 'get',
    params
  })
}

// 获取销售订单详情
export function getSalesOrderDetail(salesOrderId: number) {
  return request<SalesOrder>({
    url: `/sales-order/${salesOrderId}`,
    method: 'get'
  })
}

// 新增销售订单
export function addSalesOrder(data: Partial<SalesOrder>) {
  return request({
    url: '/sales-order',
    method: 'post',
    data
  })
}

// 修改销售订单
export function updateSalesOrder(data: Partial<SalesOrder>) {
  return request({
    url: '/sales-order',
    method: 'put',
    data
  })
}

// 删除销售订单
export function deleteSalesOrder(salesOrderId: number) {
  return request({
    url: `/sales-order/${salesOrderId}`,
    method: 'delete'
  })
}


